package com.bw.servlet;

import com.bw.dao.UserDao;
import lombok.SneakyThrows;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/***************************
 FileAction:

 CreateTime:2022-04-12 10:20
 Author:Aaking-aline
 ****************************/
@WebServlet("/LoginServlet")
public class LoginServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    @SneakyThrows
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String username = request.getParameter("username");
        String password = request.getParameter("password");


        boolean b = new UserDao().selectUser(username, password);

        if(b){
            request.setAttribute("username",username);
            request.getRequestDispatcher("message.jsp").forward(request,response);
            return ;
        }

        response.sendRedirect("index.jsp");
    }
}
